<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img {
            width: 200px;
            height: 300px;
        }
    </style>
</head>

<body>

    <script>
        let arr = ["1.jpg",
                "2.png",
                "http://img.desktx.com/d/file/wallpaper/scenery/20170209/ca186d97701674b996264b2d352894a7.jpg"
            ]
        function loaded() {
            alert("Images loaded")
        }

        function preloadImages(sources, callback) {
            let count = 0;
            for (var i = 0; i < sources.length; i++) {
                let img = document.createElement('img');
                img.src = sources[i];
                img.onload = function() {
                    count++;
                    document.body.append(img)
                    console.log(count);
                    if (count == sources.length) {
                        callback()

                    }
                }
                img.onerror = function() {
                    count++;
                    console.log(count);
                    document.body.append(img)
                }
            }
        }
        preloadImages(arr, loaded);
    </script>
</body>

</html>